<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JQuery easyui demo</title>

<style type="text/css">
#user_fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}

.fitem input {
	width: 160px;
}
</style>


<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.4.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.4.1/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.4.1/themes/color.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.4.1/demo/demo.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.4.1/${pageContext.request.contextPath}/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.4.1/${pageContext.request.contextPath}/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
	<table id="deviceType_dg" class="easyui-datagrid" style="height: 900px;"
		url="${pageContext.request.contextPath}/admin/deviceType/findAll.do" toolbar="#deviceType_toolbar" pagination="true"
		rownumbers="true" fitColumns="true" singleSelect="true"
		data-options="fit:false,border:false,pageSize:10,pageList:[10,20,30,40]">
		<thead>		
			<!-- 管理表格-表头的修改 -->
			<tr>
				<th field="sortNo" width="50">要闻编号</th>
				<th field="sortName" width="50">要闻类型</th>
			</tr>
		</thead>
	</table>
	
	<div id="deviceType_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newdeviceType()">新增</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editdeviceType()">编辑</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroydeviceType()">删除</a>
	</div>

	<div id="deviceType_dlg" class="easyui-dialog" style="padding: 10px 20px"
		closed="true" buttons="#deviceType_dlg-buttons">
		<div class="ftitle">详细信息</div>
		<form id="deviceType_fm" method="post" novalidate>
			<div class="fitem">
				<label>要闻类型:</label> <input name="sortName" class="easyui-textbox"
					required="true">
			</div>
		</form>
	</div>
	
	<div id="deviceType_dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-ok" onclick="savedeviceType()" style="width: 90px">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#deviceType_dlg').dialog('close')"
			style="width: 90px">取消</a>
	</div>
	<script type="text/javascript">	
		var url;
		function newdeviceType() {
			$('#deviceType_dlg').dialog('open').dialog('setTitle', '新增');
			$('#deviceType_fm').form('clear'); //清除表单数据
			url = '${pageContext.request.contextPath}/admin/deviceType/addDeviceType.do'; //按新增 调用的网址	
		}
		
		function editdeviceType() {
			var row = $('#deviceType_dg').datagrid('getSelected');
			if (row) {
				$('#deviceType_dlg').dialog('open').dialog('setTitle', '编辑'); //打开对话框
				$('#deviceType_fm').form('clear');   //清除表单数据
				$('#deviceType_fm').form('load', row);  //重新加载数据
				url = '${pageContext.request.contextPath}/admin/deviceType/updateDeviceType.do?sortNo=' + row.sortNo;
			}
		}
		function savedeviceType() {
			$('#deviceType_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.errorMsg) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$('#deviceType_dlg').dialog('close'); // close the dialog
						$('#deviceType_dg').datagrid('reload'); // reload the user data
					}
				}
			});
		}
		function destroydeviceType() {
			var row = $('#deviceType_dg').datagrid('getSelected');
			if (row) {
				$.messager.confirm('Confirm', '确定要删除吗?', function(r) {
					if (r) {   //ajax调用-异步通信调用
						$.post('${pageContext.request.contextPath}/admin/deviceType/deleteDeviceType.do', {
							sortNo : row.sortNo
						}, function(result) {
							if (result.success) {
								$('#deviceType_dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show({ // show error message
									title : 'Error',
									msg : result.errorMsg
								});
							}
						}, 'json');  //回调函数
					}
				});
			}
		}
	</script>

</body>
</html>